import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:largefriends/res/lf_color.dart';
import 'package:largefriends/res/lf_fonts.dart';
import 'package:loading_animation_widget/loading_animation_widget.dart';

void hideLoading() {
  if (Get.isDialogOpen == true) {
    Get.until((route) => Get.isDialogOpen == false);
  }
}

void hideDialog() {
  if (Get.isDialogOpen == true) {
    Get.until((route) => Get.isDialogOpen == false);
  }
}

void hideSheet() {
  if (Get.isBottomSheetOpen == true) {
    Get.until((route) => Get.isBottomSheetOpen == false);
  }
}

/// canPopScope 按back键是否自动消失,默认不消失
/// barrierDismissible 点击空白是否消失,默认不消失
void showLoading({bool canPopScope = false, bool barrierDismissible = false}) {
  Get.dialog(
      WillPopScope(
          child: Container(
              color: color210215.withAlpha(64),
              alignment: Alignment.center,
              child: Container(
                width: 120.r,
                height: 120.r,
                padding: EdgeInsets.only(bottom: 10.h),
                decoration: BoxDecoration(
                    color: colorFEFEFE,
                    borderRadius: BorderRadius.circular(14.r)),
                alignment: Alignment.center,
                child: SizedBox(
                  width: 60.r,
                  height: 60.r,
                  child: LoadingAnimationWidget.dotsTriangle(
                    color: color210215,
                    size: 60.r,
                  ),
                ),
              )),
          onWillPop: () async {
            return canPopScope;
          }),
      barrierDismissible: barrierDismissible,
      barrierColor: colorFEFEFE.withAlpha(64));
}

// void showWinkDialog() {
//   Get.dialog(
//       WillPopScope(
//           child: Container(
//               color: color210215.withAlpha(64),
//               alignment: Alignment.center,
//               child: Container(
//                 width: 180.r,
//                 height: 150.r,
//                 decoration: BoxDecoration(
//                     color: colorFEFEFE,
//                     borderRadius: BorderRadius.circular(20.r)),
//                 alignment: Alignment.center,
//                 child: SizedBox(
//                   width: 60.r,
//                   height: 60.r,
//                   child: Lottie.asset(Res.wink),
//                 ),
//               )),
//           onWillPop: () async {
//             return false;
//           }),
//       barrierDismissible: false,
//       barrierColor: colorFEFEFE.withAlpha(64));
// }

void showSnackBar(String message) {
  if (message.trim().isEmpty) {
    return;
  }
  if (Get.isSnackbarOpen) {
    return;
  }
  var duration = (message.trim().length > 30) ? 4000 : 2000;
  Get.showSnackbar(GetSnackBar(
    snackPosition: SnackPosition.TOP,
    borderRadius: 15,
    margin: const EdgeInsets.symmetric(horizontal: 10),
    padding: const EdgeInsets.all(16),
    duration: Duration(milliseconds: duration),
    barBlur: 7.0,
    backgroundColor: color210215,
    dismissDirection: DismissDirection.up,
    snackStyle: SnackStyle.FLOATING,
    forwardAnimationCurve: Curves.easeOutCirc,
    reverseAnimationCurve: Curves.easeOutCirc,
    animationDuration: const Duration(milliseconds: 500),
    overlayBlur: 0.0,
    overlayColor: Colors.transparent,
    messageText: Text(
      message,
      textAlign: TextAlign.center,
      style: TextStyle(
          color: colorFEFEFE, fontSize: 15.sp, fontFamily: fontMedium),
    ),
  ));
}
